package com.sjy.springcloud.controller;

import com.sjy.springcloud.entities.CommonResult;
import com.sjy.springcloud.entities.Payment;
import com.sjy.springcloud.service.impl.PaymentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @program: microservice2022
 * @description: 支付接口
 * @author: Mr.abel(ShiJiaYi)
 * @create: 2022-01-14 13:52
 **/
@RestController
@Slf4j
public class PaymentController {
    @Resource
    private PaymentService paymentService;

    @PostMapping("/payment/create")
    public CommonResult commonResult(@RequestBody Payment payment){
        int result = paymentService.createPayment(payment);
        log.info("插入结果"+result);
        if(result > 0){
            return new CommonResult(200,"插入成功");
        }else{
            return new CommonResult(-101,"插入失败");
        }
    }

    @GetMapping("/payment/get/{id}")
    public CommonResult getPaymentById(@PathVariable("id") long id){
        Payment payment = paymentService.getPaymentById(id);
        log.info("插入结果"+payment);
        if(payment != null){
            return new CommonResult(200,"查询成功",payment);
        }else{
            return new CommonResult(-102,"查询失败");
        }
    }
}
